package com.example.controller;

import com.example.pojo.Order;
import com.example.pojo.PageBean;
import com.example.pojo.Result;
import com.example.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    @GetMapping
    public Result select(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize,
                         @RequestParam(defaultValue = "0") int materialID, @RequestParam(defaultValue = "0") int quantity,String status,
                         @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        PageBean pageBean = orderService.page(page, pageSize, materialID, quantity, status ,begin, end);
        return Result.success(pageBean);
    }
    @PostMapping
    public Result add(@RequestBody Order order){
        orderService.add(order);
        return Result.success();
    }
    @DeleteMapping("/{ids}")
    public Result deletes(@PathVariable List<Integer> ids){
        orderService.deletes(ids);
        return Result.success();
    }

    @PostMapping("/finish")
    public Result orderFinish(@RequestBody Order order){
        orderService.finishOrder(order);
        return Result.success();
    }
}
